1 | 'use strict';
|
2 |
|
3 | var Path = require('path');
|
4 | var Should = require('should');
|
5 | var debug = require('debug')('ifnode:test:components');
|
6 |
|
7 | var IFNode = require('../');
|
8 | var app = IFNode({
|
9 | project_folder: Path.resolve(__dirname, '../examples/components'),
|
10 | env: 'local',
|
11 | alias: 'cmpts'
|
12 | }).load();
|
13 |
|
14 | describe('Components', function() {
|
15 | describe('app.component(id: string)', function() {
|
16 | it('should initialize component', function() {
|
17 | app.component('first').should.be.an.Object();
|
18 | app.component('component-in-folder').should.be.a.String();
|
19 |
|
20 | app.component('ClassES5').should.be.a.Function();
|
21 | app.component('ClassES5Component').should.be.not.a.Function();
|
22 | });
|
23 |
|
24 | it('should append methods', function() {
|
25 | app.component('third').custom().should.be.equal('is_custom');
|
26 | });
|
27 |
|
28 | it('should load internal component modules', function() {
|
29 | Should.equal(app.component('can-load-internal/other'), 'can-load-internal/other');
|
30 | });
|
31 |
|
32 | it('should be equal to app attached components', function() {
|
33 | Should.equal(app.first, app.component('first'));
|
34 | })
|
35 | });
|
36 |
|
37 | describe('app.Component(custom_component_config?: Object)', function() {
|
38 | it('should exists', function () {
|
39 | app.Component.should.be.a.Function();
|
40 | });
|
41 |
|
42 | it('default options', function() {
|
43 | app.components.first.config.value.should.be.equal(1);
|
44 | app.components.second.config.should.be.equal('value');
|
45 | app.components.third.config.should.have.properties({});
|
46 | });
|
47 |
|
48 | it('application instance options', function() {
|
49 | app.first.config.value.should.be.equal(1);
|
50 | app.second.config.should.be.equal('value');
|
51 | app.third.config.should.have.properties({});
|
52 | });
|
53 | });
|
54 |
|
55 | describe('ES5: Class', function() {
|
56 | var ClassES5 = app.component('ClassES5');
|
57 |
|
58 | Should.equal(ClassES5.STATIC, 'ClassES5.STATIC');
|
59 | Should.equal(ClassES5.getStatic(), 'ClassES5.STATIC');
|
60 | Should.equal(ClassES5.getName(), 'ClassES5');
|
61 |
|
62 | Should.equal((new ClassES5).plain(), 'ClassES5#plain');
|
63 | });
|
64 |
|
65 | describe('ES5: Class-based component', function() {
|
66 | Should.equal(app.ClassES5Component.plain(), 'ClassES5Component#plain');
|
67 | });
|
68 |
|
69 | describe('ES6: Class-based component through several inherits', function() {
|
70 | Should.equal(app.ClassES5ComponentDoubleInherits.base_plain(), 'Base#base_plain');
|
71 | Should.equal(app.ClassES5ComponentDoubleInherits.plain(), 'ClassES5ComponentDoubleInherits#child_plain');
|
72 | });
|
73 |
|
74 | describe('component instance', function() {
|
75 | it('.initialize(config: Object)', function () {
|
76 | app.second.initialized.should.be.true();
|
77 | });
|
78 |
|
79 | it('component has alias', function() {
|
80 | app.second.should.be.equal(app.second_alias);
|
81 | Should.not.exist(app.third_alias);
|
82 | });
|
83 |
|
84 | it('custom method', function() {
|
85 | app.third.custom().should.be.equal('is_custom');
|
86 | });
|
87 | });
|
88 | });
|